package com.example.yb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.yb.entity.Iyqww_yb_wbssb_1w1m;
import com.example.yb.entity.Iyqww_yb_wbssb_1w1mtb;
import com.example.yb.entity.Iyqww_yb_wbssb_ssb;
import com.example.yb.entity.Iyqww_yb_wbssb_ssbVo;
import com.example.yb.service.YBService;
import com.example.yb.service.impl.YBServiceImpl;
import com.example.yl.entity.Iyqww_YL_1w1mtb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Map;

/**
 * @author
 * @createtime 2021-08-13 11:16
 * @description
 */
@RestController
@RequestMapping("/yb")
public class YBContorller {

    @Autowired
    private YBService ybService;


    /**
     * transferredList 已办结
     *
     * @param pagenum
     * @param pageSize
     * @param foreignId
     * @return
     */
    @RequestMapping("/transferredList")
    public Page<Iyqww_yb_wbssb_ssbVo> itemList(@RequestParam(defaultValue = "1") Integer pagenum,
                                               @RequestParam(defaultValue = "5") Integer pageSize,
                                               @RequestParam String foreignId) {

        Page<Iyqww_yb_wbssb_ssbVo> page = new Page<>(pagenum, pageSize);
        Page<Iyqww_yb_wbssb_ssbVo> pageList = page.setRecords(ybService.queryAllSsbVo(page, foreignId));
        System.out.println(page);


        System.out.println("============================");
        pageList.hasNext();
        System.out.println("是否有下一页:" + pageList.hasNext());
        System.out.println("当前页:" + pageList.getCurrent());
        System.out.println("总数：" + pageList.getTotal());
        System.out.println("getPages():" + pageList.getPages());
        System.out.println("getOrders():" + pageList.getOrders());
        System.out.println("getSize():" + pageList.getSize());

        return pageList;
    }


    /**
     * ntransferredList 未办结
     *
     * @param pagenum
     * @param pageSize
     * @param foreignId
     * @return
     */
    @RequestMapping("/ntransferredList")
    public Page<Iyqww_yb_wbssb_ssbVo> itemList1(@RequestParam(defaultValue = "1") Integer pagenum,
                                                @RequestParam(defaultValue = "5") Integer pageSize,
                                                @RequestParam String foreignId) {

        Page<Iyqww_yb_wbssb_ssbVo> page = new Page<>(pagenum, pageSize);
        Page<Iyqww_yb_wbssb_ssbVo> pageList = page.setRecords(ybService.queryAllSsbVo1(page, foreignId));
        System.out.println(page);


        return pageList;
    }


    /**
     * 查询 填报表中的所需的基本数据
     *
     * @return
     */
    @RequestMapping("/selectAll")
    @ResponseBody
    public ArrayList<Map<String, Object>> selectAll() {
        ArrayList<Map<String, Object>> list = ybService.selectAll();
        return list;
    }


    /**
     * 查询 填报表中的所需的基本数据
     *
     * @return
     */
    @RequestMapping("/findEssential")
    @ResponseBody
    public ArrayList<Map<String, Object>> findEssential() {
        ArrayList<Map<String, Object>> list = ybService.findEssential();
        return list;
    }

    /**
     * 根据地址设置唯一标识值
     *
     * @return
     */
    @RequestMapping("/address")
    public ArrayList<Iyqww_yb_wbssb_1w1mtb> findAddress() {
        ArrayList<Iyqww_yb_wbssb_1w1mtb> adds = ybService.findAddress();

        String str;
        String address;
        Iyqww_YL_1w1mtb tb = new Iyqww_YL_1w1mtb();
        int demo = 100000;
        for (int i = 0; i < adds.size(); i++) {
            demo += 1;
            str = "yb" + demo;
            address = adds.get(i).getAddress();
            //根据地址给唯一标识赋值
            ybService.addForeignId(str, address);
        }

        System.out.println(adds);
        return adds;
    }

    /**
     * 随手报表同步一物一码填报表中的唯一标识
     *
     * @return
     */
    @RequestMapping("/update")
    public ArrayList<Iyqww_yb_wbssb_ssb> findAddress1() {
        ArrayList<Iyqww_yb_wbssb_ssb> adds = ybService.findAddress1();
        ArrayList<Iyqww_yb_wbssb_1w1mtb> adds_tb = ybService.findAddress();
        System.out.println(adds_tb);
        String address;//address
        String foreignId;

        for (int i = 0; i < adds.size(); i++) {
            for (int j = 0; j < adds_tb.size(); j++) {

                //判断随手报中的地址是否与一物一码填报中的地址相同
                if (adds.get(i).getAddress().equals(adds_tb.get(j).getAddress())) {
                    address = adds.get(i).getAddress();
                    foreignId = adds_tb.get(j).getForeignId();
                    //System.out.println(address);
                    //System.out.println(foreignId);
                    ybService.addForeignId1(foreignId, address);
                }
            }
        }

        return null;

    }


    /**
     * 一物一码表同步一物一码填报表中的唯一标识
     *
     * @return
     */
    @RequestMapping("/update2")
    public ArrayList<Iyqww_yb_wbssb_1w1m> findAddress2() {
        ArrayList<Iyqww_yb_wbssb_1w1m> adds = ybService.findAddress2();

        ArrayList<Iyqww_yb_wbssb_1w1mtb> adds_tb = ybService.findAddress();
        System.out.println(adds_tb);

        String address;//address
        String foreignId_val;

        for (int i = 0; i < adds.size(); i++) {
            for (int j = 0; j < adds_tb.size(); j++) {

                if (adds.get(i).getAddress().equals(adds_tb.get(j).getAddress())) {
                    address = adds.get(i).getAddress();
                    foreignId_val = adds_tb.get(j).getForeignId();
                    //System.out.println(address);
                    //System.out.println(foreignId);
                    ybService.addForeignId_val(foreignId_val, address);
                }
            }
        }
        return null;
    }

    /**
     * 查询1w1mtb中的数据并处理在存到vo表中
     */
    @RequestMapping("/set")
    public void set() {
        ybService.setssbVoinfo();
    }

<<<<<<< HEAD




=======
    /**
     * 根据唯一标识修改经纬度
     */
    @RequestMapping("/set1")
    public void update() {
        ybService.updateVoinfo();
    }
>>>>>>> 3f039bc935edf091c1f1437e0c1ddcf82f9a410e
}
